package perform.database;

import java.lang.reflect.Field;
import perform.annotations.OneToOne;
import perform.constants.Index;
import perform.mappings.ClassMappings;

public class OneToOneProcessor extends ForeignKeyProcessor {
	
	private OneToOne oneToOne;
	
	public OneToOneProcessor(Field field, String name){
		super(field, name);
		oneToOne = field.getAnnotation(OneToOne.class);
		target = oneToOne.target();
		idColumn = ClassMappings.getIDColumnProcessor(target);
		name = oneToOne.name();
		if(name.equals("")){
			name = field.getName();
		}
		cascade = oneToOne.cascade();
		if(name.equals("")){
			name = field.getName();
		}
		buildColumnDefinition();
		buildIndexDefinition();
		buildForeignDefinition();
	}

	@Override
	public boolean isNullable() {
		return oneToOne.nullable();
	}

	@Override
	public boolean isIndex() {
		return true;
	}

	@Override
	public Index getIndex() {
		return Index.UNIQUE;
	}

}
